package org.micro.test.annotation;

import com.sun.source.util.Trees;
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Name;

import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import java.util.Set;

@SupportedAnnotationTypes({"org.micro.test.annotation.MicroTest"})
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public class MicroProcessor extends AbstractProcessor {
    private int tally;
    private Trees trees;
    private TreeMaker make;
    private Name.Table names;
    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {//具体处理注解的逻辑，控制代码的生成
        System.out.println("----------------Annotation Processing--------------");
        return true;
    }

    protected MicroProcessor() {
        super();
    }

    @Override
    public Set<String> getSupportedOptions() {
        return super.getSupportedOptions();
    }

    @Override
    public synchronized void init(ProcessingEnvironment processingEnv) {  // 主要做一些初始化操作
//        System.out.println("----------------AnnotationProcessing init!--------------");
//        super.init(processingEnv);
//        trees = Trees.instance(processingEnv);
//        Context context =((JavacProcessingEnvironment) processingEnv).getContext();
//        make = TreeMaker.instance(context);
//        names = Name.Table.instance(context);
//        tally = 0;
    }

    @Override
    public Iterable<? extends Completion> getCompletions(Element element, AnnotationMirror annotation, ExecutableElement member, String userText) {
        return super.getCompletions(element, annotation, member, userText);
    }

    @Override
    protected synchronized boolean isInitialized() {
        return super.isInitialized();
    }
}
